package org.example.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZerlindaLi create at 2021/3/30 16:44
 * @version 1.0.0
 * @description Branch
 */
public class Branch extends Tree{

    private Integer level;

    private List<Tree> trees;

    public Branch(String name, Integer level) {
        super(name);
        this.level = level;
        this.trees = new ArrayList<>();
    }

    @Override
    public void show() {
        System.out.println(this.name);
        for(Tree tree : trees) {
            if(level != null) {
                for(int i = 0; i < level; i++) {
                    System.out.print(" ");
                }
                for(int i = 0; i < level; i++) {
                    if(i == 0) System.out.print("+");
                    System.out.print("-");
                }
            }
            tree.show();
        }
    }

    public boolean addChild(Tree tree) {
        return trees.add(tree);
    }

    public boolean removeChild(Tree tree) {
        return trees.remove(tree);
    }
}
